package ncov.service.impl;

import ncov.dao.LocalAuthDao;
import ncov.model.LocalAuth;
import ncov.service.LocalAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author WuChangJian
 * @date 2020/6/7 9:35
 */
@Service
@Transactional
public class LocalAuthServiceImpl implements LocalAuthService {
    @Autowired
    private LocalAuthDao localAuthDao;

    @Override
    public LocalAuth getOneByNameAndPwd(LocalAuth localAuth) {
        List<LocalAuth> localAuthList;
        if (localAuth.getUsername() != null && localAuth.getPassword() != null) {
            localAuthList = localAuthDao.queryAll(localAuth);
            if (localAuthList.size() == 1)
                return localAuthList.get(0);
        }
        return null;
    }

    @Override
    public LocalAuth update(LocalAuth localAuth) {
        localAuthDao.update(localAuth);
        return localAuth;
    }

}
